package com.ruoyi.task.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.task.domain.TaskSpecial;
import com.ruoyi.task.service.ITaskSpecialService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 特殊情况发生管理Controller
 *
 * @author ruoyi
 * @date 2023-08-03
 */
@RestController
@RequestMapping("/task/special")
public class TaskSpecialController extends BaseController
{
    @Autowired
    private ITaskSpecialService taskSpecialService;

    /**
     * 查询特殊情况发生管理列表
     */
    @PreAuthorize("@ss.hasPermi('task:special:list')")
    @GetMapping("/list")
    public TableDataInfo list(TaskSpecial taskSpecial)
    {
        startPage();
        List<TaskSpecial> list = taskSpecialService.selectTaskSpecialList(taskSpecial);
        return getDataTable(list);
    }

    /**
     * 导出特殊情况发生管理列表
     */
    @PreAuthorize("@ss.hasPermi('task:special:export')")
    @Log(title = "特殊情况发生管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TaskSpecial taskSpecial)
    {
        List<TaskSpecial> list = taskSpecialService.selectTaskSpecialList(taskSpecial);
        ExcelUtil<TaskSpecial> util = new ExcelUtil<TaskSpecial>(TaskSpecial.class);
        util.exportExcel(response, list, "特殊情况发生管理数据");
    }

    /**
     * 获取特殊情况发生管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('task:special:query')")
    @GetMapping(value = "/{specialId}")
    public AjaxResult getInfo(@PathVariable("specialId") Long specialId)
    {
        return success(taskSpecialService.selectTaskSpecialBySpecialId(specialId));
    }

    /**
     * 新增特殊情况发生管理
     */
    @PreAuthorize("@ss.hasPermi('task:special:add')")
    @Log(title = "特殊情况发生管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TaskSpecial taskSpecial)
    {
        return toAjax(taskSpecialService.insertTaskSpecial(taskSpecial));
    }

    /**
     * 修改特殊情况发生管理
     */
    @PreAuthorize("@ss.hasPermi('task:special:edit')")
    @Log(title = "特殊情况发生管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TaskSpecial taskSpecial)
    {
        return toAjax(taskSpecialService.updateTaskSpecial(taskSpecial));
    }

    /**
     * 删除特殊情况发生管理
     */
    @PreAuthorize("@ss.hasPermi('task:special:remove')")
    @Log(title = "特殊情况发生管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{specialIds}")
    public AjaxResult remove(@PathVariable Long[] specialIds)
    {
        return toAjax(taskSpecialService.deleteTaskSpecialBySpecialIds(specialIds));
    }
}
